<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of proxyAction
 *
 * @author User
 */

class MakeQueryAfterTime {
    public function __invoke(multiCURL $curl) {
        $curl->startFilter->addBoth(function($arg) {
            $def = new Deferred();
            setTimeout(function() use($arg, $def) {
                $def->callback($arg);
            }, 5);
            return $def;
        });
    }
};
class FilterByContent {
    
    /**
     * @param callback $filter 
     */
    public function __construct($filter) {
        $this->filter = $filter;
    }
    
    public function __invoke(multiCURL $curl) {
        $filter = &$this->filter;
        $curl->endFilter->addBoth(function(multiCURL $curl) use($filter) {
            try {
                $filtered = call_user_func($filter, $curl->result);
                if(!$filtered) {
                    throw new Exception('NOt FIltered');
                }
            } catch(Exception $e) {
                $curl->error[] = $e->getMessage();
            }
            return $curl;
        });
    }
};
class proxyAction {
    
    public function __invoke(multiCURL $curl) {
        $this->proxy = $this->getProxy();
        $curl->setopt_array(array(
            CURLOPT_PROXY => $this->proxy
        ));
        $_this = $this;
        $curl->addEventListener('onLoad', function(Event $event) use($_this) {
            proxyAction::DisposeProxy($event->target->setopt[CURLOPT_PROXY]);
        });
    }
    public function getProxy() {
        return '';
    }
    public function DisposeProxy($proxy) {
        
    }
};
class proxySession {
    public function __construct() {
        $this->proxy = '';
        $this->cookie = '';
    }
    public function __invoke(multiCURL $curl) {
        $curl->setopt_array(array(
            CURLOPT_PROXY      => $this->proxy,
            CURLOPT_COOKIEFILE => $this->cookie,
            CURLOPT_COOKIEJAR  => $this->cookie
        ));
        $_this = $this;
        $curl->addEventListener('onLoad', function(Event $event) use($_this) {
            proxyAction::DisposeProxy($event->target->setopt[CURLOPT_PROXY]);
        });
    }
    public function DisposeProxy($proxy) {
        
    }
    
};

?>
